/**
* 注册及配置 vuex 插件
* Author: dong xing
* Date: 2019-01-24
* Time: 15:43
* Email: dong.xing@outlook.com
*/

import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'
import getters from './getters'
import alarm from './modules/alarm'
import auth from './modules/auth'
import form from './modules/form'
import manage from './modules/manage'
import monitor from './modules/monitor'
import permission from './modules/permission'
import project from './modules/project'
import view from './modules/view'

Vue.use(Vuex)

export default new Vuex.Store({
  modules: {
    alarm,
    auth,
    form,
    manage,
    monitor,
    permission,
    project,
    view
  },
  getters,
  plugins: [
    createPersistedState({
      // 当刷新时将state持久化于sessionStorage中
      storage: window.sessionStorage,
      reducer: (state) => {
        let sessionState = Object.assign({}, state)

        // 不将权限信息持久化
        delete sessionState.permission
        return sessionState
      }
    })
  ]
})
